const { default: axios } = require('axios');
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  // 部署生产环境和开发环境下的URL。
  // 默认情况下，Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上，你就需要用这个选项指定这个子路径。例如，如果你的应用被部署在 https://www.ruoyi.vip/admin/，则设置 baseUrl 为 /admin/。
  publicPath: process.env.NODE_ENV === "production" ? "/static/modification/" : "/",
  chainWebpack: config => {
    //路径配置
    config.resolve.alias
      .set('@', resolve('src'))
      .set('api', resolve('src/api'))
      .set('components', resolve('src/components'))
  },
  css: {
    loaderOptions: {
      scss: {
        prependData: `
          @import "@/common/scss/_variables.scss";
          @import "@/common/scss/_mixins.scss";
          `
      }
    }
  },
  lintOnSave: false,
  //请求代理
  devServer: {
    host: '0.0.0.0',
    port: 8080,
    before(app) {
      app.get('/api/getStatistics', function (req, res) {
        var url = process.env.VUE_APP_BASE_API + '/cats/lv2/statistics';
        axios.get(url).then((response) => {
          res.json(response.data)
        }).catch((e) => {
          // console.log(e)
        })
      }),
        app.get('/api/getRanking', function (req, res) {
          var url = process.env.VUE_APP_BASE_API + '/ranking/gender';
          axios.get(url).then((response) => {
            res.json(response.data)
          }).catch((e) => {
            // console.log(e)
          })
        }),
        app.get('/api/rankingById', function (req, res) {
          var url = process.env.VUE_APP_BASE_API + '/ranking/' + req.query.id;
          axios.get(url).then((response) => {
            res.json(response.data)
          }).catch((e) => {
            console.log('e')
          })
        })
    }
  }
}